package com.ruoyi.common.utils.pdfbox;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.IOException;
import java.io.InputStream;

/**读取pdf内容
 *
 */
public class PdfUtils {

    /**
     * 读取pdf文件内容
     * @param is
     * @return
     */
    public String readFile(InputStream is){
        PDDocument document = null;
        String text = null;
        try {
            document = PDDocument.load(is);
            PDFTextStripper pdfStripper = new PDFTextStripper();
            text = pdfStripper.getText(document);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (document != null) {
                try {
                    document.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return text;
    }
}
